package com.box.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.box.service.BlogService;
import com.box.service.lucene.BlogIndexService;
import com.box.service.search.SearchBlogService;
import com.box.service.search.SearchService;
import com.box.utils.JsonUtils;
import com.box.utils.PageView;
import com.box.utils.ResponseResult;

/**   
*    
* 项目名称：MyBox   
* 类名称：SearchController   
* 类描述：   搜索控制类ajax
* 创建人：君无邪   
* 创建时间：2019年11月19日 下午11:28:18   
* 修改备注：  https://www.java214.com 
* @version    1.0
*    
*/ 
@Controller
@RequestMapping("/search")
public class SearchController {
	
	@Autowired
	private BlogService blogService;
	
	@Autowired
	private SearchService searchService;
	
	@RequestMapping(value="/q",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String search(String keyword,String page,HttpServletResponse response) throws Exception{
		
		System.out.println("搜索页面的page:"+page);
		System.out.println("搜索页面的内容值:"+keyword);
		PageView pageview = blogService.searchBlogEntityByKeyWords(keyword, page);
		if(pageview!=null){
			return JsonUtils.objectToJson2(pageview.getBaidu(), response, pageview.getListType());
		}else{
			return JsonUtils.objectToJson(404);
		}
		

	}
	
	
	
	@RequestMapping(value="/solr/q",method={RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public String SearchLiet(@RequestParam(defaultValue="博客",required=false) String keyword,@RequestParam(defaultValue="1")  String page,HttpServletResponse response) throws Exception{
	
	
	System.out.println(keyword+"................solrj的查询值");
	System.out.println("页面第一页:"+page);
		PageView search = searchService.search(keyword, page);
		if(search!=null){
			return JsonUtils.objectToJson2(search.getBaidu(), response, search.getListType());
		}else{
			return JsonUtils.objectToJson(404);
		}
		
	

	}
	

}
